package com.we823.cms.controller.manage.ex;

import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.PageInfo;
import com.we823.cms.common.web.pageable.Direction;
import com.we823.cms.common.web.pageable.PageRequest;
import com.we823.cms.common.web.pageable.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.we823.cms.common.WebConstants;
import com.we823.cms.controller.manage.AbstractManageController;
import com.we823.cms.model.extension.CaseModel;
import com.we823.cms.repository.service.extension.CaseService;

@Controller
@RequestMapping(WebConstants.MANAGE_URL+"/case")
public class CaseManageController extends AbstractManageController<CaseModel, Integer> {

	private String baseUrl = WebConstants.MANAGE_URL+"/case/";
	
	private CaseService caseService;
	
	@Autowired
	public CaseManageController(CaseService caseService) {
		super(caseService);
		this.caseService=caseService;
		super.baseUrl=baseUrl;
		super.entityName="caseModel";
	}

	@Override
	public PageInfo<CaseModel> getData(PageRequest pageRequest,
									   HttpServletRequest request, Model model, boolean pageable) {
		PageInfo<CaseModel> casePage ;
		if (pageable) {
			casePage = caseService.findAll(pageRequest);
		}else {
			casePage = new PageInfo<>(caseService.findAll(getSort(request)));
		}
		return casePage;
	}
	
	@Override
	public Sort getSort(HttpServletRequest request) {
		Sort sort = super.getSort(request);
		if (sort==null) {
			sort = new Sort(Direction.DESC,"addtime");
		}
		return sort;
	}

	@Override
	public void setIndetity() {
		setResourceIdentity("ex:case");
	}

}
